<template>
  <section class="_m-2">
    <div class="title d-flex justify-content-between">
      <h3>查看相关类型的小说</h3>
      <h3 @click="refreshData">
        <i class="iconfont icon-huanyihuan"></i> 换一换
      </h3>
    </div>
    <eight-grid :data="booksList" :es="true"></eight-grid>
  </section>
</template>

<script>
import EightGrid from "@/views/components/EightGrid";

import {getBooksList} from 'api/BooksApi'

export default {
  name: "SectionBooks",
  components: {
    EightGrid
  },
  props: {
    sortId: Number
  },
  data() {
    return {
      booksList: [],
      search: {
        sortId: this.sortId,
        pageSize: 8,
        scrollId: "",
      }
    };
  },
  methods: {
    refreshData() {
      this.findListBySortIds();
    },
    findListBySortIds () {
      getBooksList(this.search).then(res => {
        if(res.meta.success) {
          this.booksList = res.data.data;
          this.search.scrollId = res.data.pagination.scrollId
        }
      });
    }
  },
  created () {
    // this.findListBySortIds();
  },
  watch: {
    sortId (newSortId) {
      this.search.sortId = newSortId
      this.findListBySortIds();
    }
  }
};
</script>

<style lang="stylus" scoped>
@import '~assets/css/style.styl';

section {
  background: #FFF;

  .title {
    height: 34px;
    font-size: 14px;
    line-height: 34px;

    h3 {
      padding-left: 2vw;
      padding-right: 2vw;
      position: relative;

      i {
        font-size: 12px !important;
        margin-right: 4px;
      }

      &:nth-child(1):after {
        content: '';
        width: 3px;
        height: 14px;
        display: inline-block;
        background: $colorPrimary;
        position: absolute;
        top: 10px;
        left: 0px;
        border-radius: 3px;
      }
    }
  }
}
</style>
